<div class = "main-view">
    <div class="left-margin top-margin"><strong class="am-text-primary am-text-lg">Banner管理</strong></div>
    <form class="am-form-inline left-margin top-margin" role="form">
        <div class="am-form-group">
            <label>Banner名称：</label> <input type="text" class="modal-input" style="height: 30px" ng-model="bannerName" >
            <label>Banner类别：</label>
            <select data-am-selected="{btnSize: 'sm'}" ng-model="bannerType" style="margin-left: 0px;">
                <option value=''>全部</option>
                <option value=1>邻里问问|本小区</option>
                <option value=2>集市</option>
                <option value=3>随便说说|周边小区</option>
            </select>
        </div>
        <!--<div class="am-form-group">-->
        <!--<label>菜单类型</label> <input type="password" class="am-form-field">-->
        <!--</div>-->
        <button type="submit" class="am-btn am-btn-primary" ng-click="search($event)" data-target = "cascad-search">搜索</button>
    </form>
    <br>
    <div class="am-btn-group am-btn-group-xs left-margin top-margin">
        <button type="button" class="am-btn am-btn-default" data-am-modal="{target: '#doc-modal-add', width: 800, height: 600}"><span class="am-icon-plus"></span>添加Banner</button>
        <button type="button" class="am-btn am-btn-default" ng-click="delete()"><span class="am-icon-trash-o"></span> 删除</button>
    </div>
    <div id = "pagination" class = "pagination"></div>
    <div class="pagination-table left-margin" id="tab_menu" style = "margin-top: 0px;">
        <form class="am-form">
            <table class="am-table-striped am-table-hover table-main">
                <thead>
                <tr>
                    <th class="table-check"><input type="checkbox" ng-click="allSelected()"></th>
                    <!--<th>序号</th>-->
                    <th>Banner名称</th>
                    <th>类别</th>
                    <th>排序</th>
                    <th>url</th>
                    <th>级别</th>
                    <th>区域</th>
                    <th>小区</th>
                    <th>开始日期</th>
                    <th>结束日期</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr ng-repeat="result in resultList"  id = "{{result.objId}}">
                    <td class="table-check"><input type="checkbox" class = "item-check"></td>
                    <!--<td>{{result.id}}</td>-->
                    <td>{{result.name}}</td>
                    <!--<td>{{result.type}}</td>-->
                    <td ng-show="result.type==1">邻里问问|本小区 </td>
                    <td ng-show="result.type==2">集市</td>
                    <td ng-show="result.type==3">随便说说|周边小区</td>
                    <td>{{result.bannerOrder}}</td>
                    <td>{{result.url}}</td>
                    <td>{{result.level}}</td>
                    <td>{{result.province.name+' '+result.city.name +' '+result.county.name+' '}}</td>
                    <td>{{result.community.communityName}}</td>
                    <td>{{result.beginDate|date:"yyyy-MM-dd HH:mm:ss"}}</td>
                    <td>{{result.endDate|date:"yyyy-MM-dd HH:mm:ss"}}</td>
                    <!--<th><span ng-show="result.is_publish==0">否</span><span ng-show="result.is_publish==1">是</span></th>-->
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">

                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" ng-click="bannerEdit(result)" ><span class="am-icon-copy"></span> 编辑</button>
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-hide-sm-only" ng-click="bannerPushShow(result)" >推送</button>
                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class = "left-margin">共<span id = 'page_number'>{{pageNumber}}</span>页 <span>{{count}}条数据</span></div>
    <!--新增框 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-add">
        <div class="am-modal-dialog">
            <div class="am-modal-hd border-bottom" style = "text-align: left;">新增Banner
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div style="position:absolute; left:9%; right:10%;">
                <div class="am-modal-bd body-area text-left">
                    <form>
                        <br>
                        <label style="width:100px">Banner名称:</label><input class="modal-input" style="width:500px" ng-model="addData.bannerName"><br>

                        <label style="width:100px">Banner类别：</label>
                        <select data-am-selected="{btnSize: 'sm'}" ng-model="addData.bannerType" style="margin-left: 0px">
                            <option value=1>邻里问问|本小区</option>
                            <option value=2>集市</option>
                            <option value=3>随便说说|周边小区</option>
                        </select>
                        <label style="width:100px">打开方式：</label>
                        <select data-am-selected="{btnSize: 'sm'}" ng-model="addData.openType" style="margin-left: 0px;">
                            <!--<option value=1>问答</option>-->
                            <option value=3>活动/H5</option>
                            <option value=4>专题</option>
                            <!--<option value=12>商品详情页</option>-->
                            <option value=14>积分商城</option>
                            <option value=16>邀请有礼</option>
                        </select>
                        <br>
                        <br>
                        <div>
                            <!--<label style="width:100px">开始时间</label><input type="datetime-local" ng-model="addData.beginDate">-->
                            <!--<label style="width:100px">结束时间</label><input type="datetime-local" ng-model="addData.endDate">-->
                            <label style="width:100px">开始时间:</label><input type="text" class="modal-input" ng-model="addData.beginDate" id ="begin_add">
                            <label style="width:100px">结束时间:</label><input type="text" class="modal-input" ng-model="addData.endDate" id ="end_add">
                        </div>
                        <br>
                        <label style="width:auto">设置Banner的区域:</label><br>
                        <div class = "city-cascading" style = "display: inline-block;" id = "cascad-search-add"></div>

                        <input type="text" class="modal-input" ng-model="cname" id = "cname_filter" ng-change="cnameFilter(cname,'add')" placeholder="搜索小区" style = "width: 200px;">
                        <table id="manyCommunity" style="width:500px;" border="0" >
                            <tr align="center">
                                <td >
                                    <select id="communities_select" multiple="multiple" ng-model="oneCommunity"
                                            style="width: 200px;height:300px;">
                                        <option ng-repeat="community in communityList" value="{{community.objId}}">{{community.communityName}}</option>
                                    </select>
                                </td>
                                <td >
                                    <input type="button" value=" >> " id="addAllCommunity" ng-click="addAllCommunity('add')" /><br /><br />
                                    <input type="button" value=" > " id="addCommunity" ng-click="addCommunity('add')" /><br /><br />
                                    <input type="button" value=" < " id="removeCommunity" ng-click="removeCommunity('add')"/><br /><br />
                                    <input type="button" value=" << " id="removeAllCommunity" ng-click="removeAllCommunity('add')"/>
                                </td>
                                <td>
                                    <select id="selCommunitys" multiple="multiple"
                                            style="width: 200px;height:300px;" ng-model="selCommunitys">

                                    </select>
                                </td>

                            </tr>
                        </table>
                        <br />
                        <!--<label class="control-label">摇奖次数(次/人)：</label>-->
                        <!--<input class="form-control" ng-model="addData.limitCount" required tabindex="5">-->
                        <!--<br />-->
                        <!--<label class="control-label">活动描述：</label><br />-->
                        <!--<textarea style="width:600px;height:200px;" ng-model="addData.activityDesc" required tabindex="5"></textarea>-->
                        <!--<br /><br />-->
                        <div class="form-group">
                            <label class="control-label"  style="width:180px" for="textinput">图片(最多可上传1张):</label>
                            <input type="file" id="images_upload"
                                   onchange="angular.element(this).scope().selectFile(this.files,'add')" multiple accept="image/*">
                            <div id="image_result" class="image-result"></div>
                        </div>
                        <br/>
                        <label class="control-label">URL：</label><br />
                        <input type="text" class = "modal-input" style = "width: 600px;display: inline-block;" ng-model="addData.url">
                        <br/>
                        <label class="control-label">Banner顺序：</label><br />
                        <input type="text" class = "modal-input" style = "width: 60px;display: inline-block;" ng-model="addData.bannerOrder">
                    </form>
                </div>
                <div class = "button-area border-top">
                    <button type="button" class="am-btn am-btn-success right-margin top-margin" ng-show="true" ng-click="add(addData,$event)" data-target = "cascad-search-add">保存</button>
                </div>
            </div>
        </div>
    </div>
    <!--编辑框 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-edit">
        <div class="am-modal-dialog">
            <div class="am-modal-hd border-bottom" style = "text-align: left;">编辑Banner
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div style="position:absolute; left:10%; right:10%;">
                <div class="am-modal-bd body-area text-left">
                    <form>
                        <br>
                        <label style="width:100px">Banner名称:</label><input class="modal-input" style="width:500px" ng-model="updateDate.name"><br>
                        <label style="width:100px">Banner类别：</label>
                        <select data-am-selected="{btnSize: 'sm'}" ng-model="updateDate.type" style="margin-left: 0px;">
                            <option value=1>邻里问问|本小区</option>
                            <option value=2>集市</option>
                            <option value=3>随便说说|周边小区</option>
                        </select>
                        <label style="width:100px">打开方式：</label>
                        <select data-am-selected="{btnSize: 'sm'}" ng-model="updateDate.openType" style="margin-left: 0px;">
                            <option value=1>问答</option>
                            <option value=3>活动/H5</option>
                            <option value=4>专题</option>
                            <option value=12>商品详情页</option>
                            <option value=14>积分商城</option>
                            <option value=16>邀请有礼</option>
                        </select>
                        <br>
                        <div>
                            <label style="width:auto">开始时间:</label><input type="text" class="modal-input" ng-model="updateDate.beginDate" id ="begin_edit">
                            <label style="width:auto">结束时间:</label><input type="text" class="modal-input" ng-model="updateDate.endDate" id ="end_edit">
                        </div>
                        <br>
                        <label>设置Banner的区域:</label><br>
                        <div class = "city-cascading" style = "display: inline-block;" id = "cascad-edit"></div>

                        <input type="text" class="modal-input" ng-model="cname_edit" id = "cname_filter_edit" ng-change="cnameFilter(cname_edit,'edit')" placeholder="搜索小区" style = "width: 200px;">
                        <table id="manyCommunity_edit" style="width:500px;" border="0" >
                            <tr align="center">
                                <td >
                                    <select id="communities_select_edit" multiple="multiple" ng-model="oneCommunity_edit"
                                            style="width: 200px;height:150px;">
                                        <option ng-repeat="community in communityList_edit" value="{{community.objId}}">{{community.communityName}}</option>
                                    </select>
                                </td>
                                <td >
                                    <input type="button" value=" >> " id="addAllCommunity_edit" ng-click="addAllCommunity('edit')" /><br/><br/>
                                    <input type="button" value=" > " id="addCommunity_edit" ng-click="addCommunity('edit')" /><br /><br/>
                                    <input type="button" value=" < " id="removeCommunity_edit" ng-click="removeCommunity('edit')"/><br/><br/>
                                    <input type="button" value=" << " id="removeAllCommunity_edit" ng-click="removeAllCommunity('edit')"/>
                                </td>
                                <td>
                                    <select id="selCommunitys_edit" multiple="multiple"
                                            style="width: 200px;height:150px;" ng-model="selCommunitys_edit">

                                    </select>
                                </td>

                            </tr>
                        </table>
                        <!--<label class="control-label">摇奖次数(次/人)：</label>-->
                        <!--<input class="form-control" ng-model="addData.limitCount" required tabindex="5">-->
                        <!--<br />-->
                        <!--<label class="control-label">活动描述：</label><br />-->
                        <!--<textarea style="width:600px;height:200px;" ng-model="addData.activityDesc" required tabindex="5"></textarea>-->
                        <!--<br /><br />-->
                        <br>
                        <div>
                            <slide>
                                <img ng-src="{{updateDate.imageURL}}" style="width: 100px;" onclick="if($(this).width()==100){
                                                    $('img').width(100);
                                                    $(this).width(360);
                                                    }else{
                                                    $(this).width(100);
                                                    };">
                            </slide>
                        </div>
                        <br>
                        <div class="form-group">
                            <label class="control-label"  style="width:180px" for="textinput">图片(最多可上传1张):</label>
                            <input type="file" id="images_upload_edit"
                                   onchange="angular.element(this).scope().selectFile(this.files,'edit')" accept="image/*">
                            <div id="image_result_edit" class="image-result"></div>
                        </div>
                        <br>
                        <label class="control-label">URL：</label>
                        <input type="text" class = "modal-input" style = "width: 600px;display: inline-block;" ng-model="updateDate.url">
                        <br>
                        <label class="control-label">Banner顺序：</label><br />
                        <input type="text" class = "modal-input" style = "width: 60px;display: inline-block;" ng-model="updateDate.bannerOrder">
                        <!--<div>-->
                            <!--<label>开始时间</label><input type="date" ng-model="updateData.beginDate" id ="begin">-->
                            <!--<label>结束时间</label><input type="date" ng-model="updateData.endDate" id ="end">-->
                            <!--date => datetime-local-->
                        <!--</div>-->
                    </form>
                </div>
                <div class = "button-area border-top">
                    <button type="button" class="am-btn am-btn-success right-margin top-margin" ng-show="true" ng-click="update(updateDate,$event)" data-target = "cascad-edit">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!--推送消息-->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-push">
        <div class="am-modal-dialog">
            <div class="am-modal-hd border-bottom" style = "text-align: left;">Banner推送
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <br>
            <div class="am-modal-bd body-area text-left">
                <form>
                    <label>消息内容：</label>
                    <textarea style="width:580px;height:150px;" ng-model="pushMsg" required tabindex="5"></textarea>
                </form>
            </div>
            <div class = "button-area border-top">
                <button type="button"  class="am-btn am-btn-success right-margin top-margin" ng-show="true" ng-click="bannerPushMsg(pushMsg)" data-target = "cascad-search-add">确认</button>
            </div>

        </div>
    </div>

    <!--loading-->
    <div class="am-modal am-modal-loading am-modal-no-btn" id="loading">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">正在推送...</div>
            <div class="am-modal-bd">
                <span class="am-icon-spinner am-icon-spin"></span>
            </div>
        </div>
    </div>
</div>

<script>

//    Date.prototype.format = function (format) {
//        var o = {
//            "M+": this.getMonth() + 1, //month
//            "d+": this.getDate(), //day
//            "h+": this.getHours(), //hour
//            "m+": this.getMinutes(), //minute
//            "s+": this.getSeconds(), //second
//            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
//            "S": this.getMilliseconds() //millisecond
//        }
//        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
//                (this.getFullYear() + "").substr(4 - RegExp.$1.length));
//        for (var k in o) if (new RegExp("(" + k + ")").test(format))
//            format = format.replace(RegExp.$1,
//                    RegExp.$1.length == 1 ? o[k] :
//                            ("00" + o[k]).substr(("" + o[k]).length));
//        return format;
//    }




    var fromDate_edit = $('#begin_edit').datetimepicker().on('changeDate', function (ev) {
        $('#begin_edit').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });

    var toDate_edit = $('#end_edit').datetimepicker().on('changeDate', function (ev) {
        $('#end_edit').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });


    var fromDate_add = $('#begin_add').datetimepicker().on('changeDate', function (ev) {
        $('#begin_add').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });

    var toDate_add = $('#end_add').datetimepicker().on('changeDate', function (ev) {
        $('#end_add').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });



</script>